package com.sy.simpleegg.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.sy.simpleegg.bean.ClearDataBean
import com.sy.simpleegg.databinding.ItemClearDataBinding
import com.sy.simpleegg.ext.logFile

class ClearCoinDataAdapter(val items: MutableList<ClearDataBean>):
    RecyclerView.Adapter<ClearCoinDataAdapter.ViewHolder>() {
        
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClearCoinDataAdapter.ViewHolder {
        val binding = ItemClearDataBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return items.size
    }

    @SuppressLint("RecyclerView")
    override fun onBindViewHolder(holder: ClearCoinDataAdapter.ViewHolder, position: Int) {
        try {
            val data = items[position]
            holder.date.text = data.date
            holder.coins.text = data.clearCount.toString()
        }catch (e: Exception){
            e.printStackTrace()
            logFile("显示清币数据异常：${e.message}")
        }
    }

    inner class ViewHolder(binding: ItemClearDataBinding): RecyclerView.ViewHolder(binding.root){
        val date: TextView = binding.tvDate
        val coins: TextView = binding.tvClearCount
    }
}